<?php
class Message {
	
	var $CI;
	var $msg = '';
	var $msg_type = '';
	
	function Message()
	{
		$this->CI =& get_instance();
		$this->CI->load->library('session');
		
		if ($this->CI->session->flashdata('message'))
		{
			$flash = $this->CI->session->flashdata('message');
			
			//$this->msg = '<div class="message ' . $flash['type'] . '">' . $flash['content'] . '</div>';
			$this->msg_type = $flash['type'];
			$this->msg = $flash['content'];
		}
		
		//$this->CI->template->assign('message', $this->msg);
		//$this->CI->template->assign('msg_class', $this->msg_class);
		//$this->CI->template->assign('msg', $this->msg);
		$this->display();
	}
	
	function set($type = 'error', $content = 'An error has occurred.', $display = FALSE)
	{
		if ($display === FALSE)
		{
			$this->CI->session->set_flashdata('message', array('type'=>$type, 'content'=>$content));
		}
		else
		{
			//$this->msg = '<div class="message ' . $type . '">' . $content . '</div>';
			$this->msg_type = $type;
			$this->msg = $content;
			
			//$this->CI->template->assign('message', $this->msg);
			//$this->CI->template->assign('msg_class', $this->msg_class);
			//$this->CI->template->assign('msg', $this->msg);
			$this->display();
		}
	}
	
	function display()
	{
		$this->CI->template->assign('msg_type', $this->msg_type);
		$this->CI->template->assign('msg', $this->msg);
	}
}